package chat.network.http;

import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.whu.zj.MyApplication;
import com.whu.zj.R;
import com.whu.zj.VolleySingleton;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import inter.Delegate;

/**
 * 同意添加好用
 * Created by Administrator on 2016/3/29.
 */
public class AgreeAddContact {

    Delegate delegate;

    AgreeContact agreeContact;

    public void setAgreeContact(AgreeContact agreeContact) {
        this.agreeContact = agreeContact;
    }

    public void setDelegate(Delegate delegate) {
        this.delegate = delegate;
    }

    public void agree()
    {
        String IP = MyApplication.share().getResources().getString(R.string.IP);
        String url ="http://"+IP+"/Chat/AgreeAddContact";
        StringRequest stringRequest = new StringRequest(Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (delegate != null)
                            delegate.onResponse(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (delegate != null)
                    delegate.onErrorResponse(error);
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map map = new HashMap();
                Gson gson = new Gson();
                map.put("data",gson.toJson(agreeContact));
                return  map;
            }

            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String temp = null;
                try {
                    temp = new String(response.data,"utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                return Response.success(temp, HttpHeaderParser.parseCacheHeaders(response));
            }
        };
        VolleySingleton.getVolleySingleton(MyApplication.share()).addToRequestQueue(stringRequest);
    }


    public static class AgreeContact {
        private String invite_from_ID;
        private String invite_to_ID;
        private String subscrip_Time;

        public String getInvite_from_ID() {
            return invite_from_ID;
        }
        public void setInvite_from_ID(String invite_from_ID) {
            this.invite_from_ID = invite_from_ID;
        }
        public String getInvite_to_ID() {
            return invite_to_ID;
        }
        public void setInvite_to_ID(String invite_to_ID) {
            this.invite_to_ID = invite_to_ID;
        }
        public String getSubscrip_Time() {
            return subscrip_Time;
        }
        public void setSubscrip_Time(String subscrip_Time) {
            this.subscrip_Time = subscrip_Time;
        }
    }

    public static class ResponseAgree {
        private String status;

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }
    }
}
